#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time    : 2025/4/18 15:10
@Author  : HZP
@File    : 3.Model流式输出.py
"""
from datetime import datetime

from dotenv import load_dotenv
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI

load_dotenv()

chat_prompt_template = ChatPromptTemplate.from_messages([
    ("system", "你是OpenAI开发的聊天机器人，请回答用户的问题，现在的时间是{now}"),
    ("human", "{query}"),
]).partial(now=datetime.now())

llm = ChatOpenAI(
    temperature=0.6,
    model="deepseek-r1:70b"
)

response = llm.stream(chat_prompt_template.invoke({"query": "你好，成都今天天气怎么样？"}))
for chunk in response:
    print(chunk.content, flush=True, end="")
